package com.vcredit.creditcat.framework.util;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;

public class Base64Util {
	/**
	 * 字符串BASE64解密
	 * 
	 * @param 需要解密的String字符串
	 * @return 解密后的String字符串
	 * @throws UnsupportedEncodingException
	 */
	public static String base64Decode(String content) {
		byte[] editorDeBase64;
		try {
			editorDeBase64 = content.getBytes("utf-8");
			Base64 base64 = new Base64();
			editorDeBase64 = base64.decode(editorDeBase64);
			String editors = new String(editorDeBase64);
			return editors;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return "";
	}

	/**
	 * 字符串BASE64加密
	 * 
	 * @param 需要加密的String字符串
	 * @return 加密后的String字符串
	 * @throws UnsupportedEncodingException
	 */
	public static String base64Encode(String content) {
		byte[] editorEnBase64;
		try {
			editorEnBase64 = content.getBytes("utf-8");
			Base64 base64 = new Base64();
			editorEnBase64 = base64.encode(editorEnBase64);
			String editors = new String(editorEnBase64);
			return editors;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return "";
	}

}
